{extend name='table'}

{block name="style"}
<style>
    .layui-table td .layui-table-cell {
        height: auto !important;
        overflow: visible;
        text-overflow: inherit;
        white-space: normal;
        word-break: break-all;
    }
    .layui-table td .layui-table-grrid-down{
        display: none;
    }
</style>
{/block}

{block name="content"}
<div class="layui-tab layui-tab-card">
    <div class="layui-tab-content">
        {include file='collect/goods/index_search'}
        <ul class="layui-tab-title">
            {foreach $type_arr  as $k=>$v}
            {if isset($type) and $type eq $k}
            <li data-open="{:sysuri('index')}?type={$k}" class="layui-this">{$v}</li>
            {else}
            <li data-open="{:sysuri('index')}?type={$k}">{$v}</li>
            {/if}
            {/foreach}
        </ul>
        <table id="CollectGoods" data-url="{:sysuri('index')}" data-target-search="form.form-search"></table>
    </div>
</div>
<script>

    var maxWidth = window.innerWidth;
    var maxHeight = window.innerHeight;

    $(function () {
        // 隐藏hover
        $('.layui-tab-content').on('mouseenter', "tr", function(){
            $(this).parents('tr').removeClass('layui-table-hover');
            $(this).find('.layui-table-grid-down').hide();
        })
        $('.layui-tab-content').on('mouseenter', ".layui-table-cell", function(){
            $(this).parents('tr').removeClass('layui-table-hover');
            $(this).siblings('.layui-table-grid-down').hide();
        })
        $('.layui-tab-content').on('mouseenter', ".no_hover", function(){
            $(this).parents('tr').removeClass('layui-table-hover');
            $(this).parent().siblings('.layui-table-grid-down').hide();
        })

        $('#CollectGoods').layTable({
            even: true, height: 'full',
            where:{type:"{$type}"},
            toolbar: '#toolbarDemo',
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'image_url', title: '{:lang("图片")}', width: 150, align: 'center',  templet:"#imgTpl"},
                {field: 'base_info', title: '{:lang("基本信息")}', width: 220, align: 'left',templet:"#baseTpl"},
                {field: 'product_info', title: '{:lang("产品信息")}', minWidth: 150, align: 'left',templet:"#productTpl"},
                {field: 'claim_platform', title: '{:lang("认领平台")}', width: 120, align: 'center', templet:"#claimTpl"},
                {field: 'create_at', title: '{:lang("时间")}', width: 200, align: 'left',templet:"#create_atTpl"},
                {field: 'operation', fixed: 'right', title: '{:lang("操作")}', width: 80, align: 'center', toolbar: '#toolbar'}
            ]]
            ,done: function(res, curr, count){

                //动态监听表头高度变化，冻结行跟着改变高度
                $(".layui-table-header tr").resize(function () {
                    $(".layui-table-header  tr").each(function (index, val) {
                        $($(".layui-table-fixed .layui-table-header table tr")[index]).height($(val).height());
                    });
                });
                //初始化高度，使得冻结行表头高度一致
                $(".layui-table-header tr").each(function (index, val) {
                    $($(".layui-table-fixed .layui-table-header table tr")[index]).height($(val).height());
                });
                //动态监听表体高度变化，冻结行跟着改变高度
                $(".layui-table-body tr").resize(function () {
                    $(".layui-table-body  tr").each(function (index, val) {
                        $($(".layui-table-fixed .layui-table-body table tr")[index]).height($(val).height());
                    });
                });
                //初始化高度，使得冻结行表体高度一致
                $(".layui-table-body tr").each(function (index, val) {
                    $($(".layui-table-fixed .layui-table-body table tr")[index]).height($(val).height());
                })
          }
        });

        // 指向元素为 `<select lay-filter="test"></select>` 的选择事件
        form.on('select(platform)', function(data){

            $.ajax({
                type : 'get',
                url  : "{:sysuri('common/ajax/getShopUserList')}",
                data : {account_id:data.value},
                success:function (res) {
                    if (res.code == 1) {
                        var html = "<option value=''>{:lang('-- 请选择 --')}</option>";

                        let data = res.data;
                        for (var i in data) {

                            html += "<option value='"+i+"'>"+data[i]+"</option>";
                        }

                        $('.user-id').html(html);
                        $('.update-user-id').html(html);

                        layui.form.render('select'); // 仅渲染 select 元素
                    }
                }
            })
        });
    });
</script>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        {if auth("claim")}
        <a class="layui-btn layui-btn-sm" data-title="{:lang('批量认领')}" data-modal='{:url("claim")}' data-table-id="CollectGoods" data-close-refresh='CollectGoods' data-rule="id#{id}">{:lang('批量认领')}</a>
        {/if}
        {if auth("remove")}
        <a class='layui-btn layui-btn-sm layui-btn-danger'data-confirm="{:lang('确定要删除吗？')}" data-table-id="CollectGoods" data-action="{:url('remove')}" data-rule="id#{id}">{:lang('批量删除')}</a>
        {/if}
    </div>
</script>

<script type="text/html" id="toolbar">
    {if auth("claim")}
    <a class="layui-btn layui-btn-primary layui-btn-xs" data-title="{:lang('认领')}" data-modal='{:url("claim")}?id={{d.id}}' data-table-id="CollectGoods" data-close-refresh='CollectGoods' data-area = "['850px','600px']">{:lang('认 领')}</a>
    {/if}
    {if auth("edit")}
    <a style="margin-left: 0;" class="layui-btn layui-btn-xs" data-title="{:lang('编辑产品')}" data-area="['{{maxWidth-210}}px', '{{maxHeight-60}}px']" data-offset="['60px','200px']" data-modal='{:url("edit")}?id={{d.id}}'>{:lang('编 辑')}</a>
    {/if}
    {if auth("remove")}
    <a style="margin-left: 0;" class="layui-btn layui-btn-xs layui-btn-danger" data-confirm="{:lang('确定要删除吗？')}" data-action="{:url('remove')}" data-value="id#{{d.id}}">{:lang('删 除')}</a>
    {/if}
</script>
<!--图片-->
<script type="text/html" id="imgTpl" >
    <img src="{{ d.main_pic }}" class="preview-all" style="max-width: 80px;max-height: 80px;" data-tips-image data-tips-hover >
</script>
<!--基本信息-->
<script type="text/html" id="baseTpl" >
    <div>
        <span>产品ID：<a target="_blank" href="{{ d.collect_url }}">{{ d.goods_code }}</a></span><br>
        <span>来源：{{ d.from_text }}</span><br>
        <span>店铺：{{ d.shop_name }}</span>
    </div>
</script>
<!--产品信息-->
<script type="text/html" id="productTpl" >
    <div>
        <span style="white-space: normal;padding-bottom:10px;word-break: break-all;font-size: 10px;color:#999;">{{ d.title }}</span><br>
        <span>SPU：{{ d.spu_code }}</span><br>
        <span>分类：[{{  d.category_code }}]{{ d.category_name }}</span><br>
        <span>价格：{{ d.min_price }} ~ {{ d.max_price }} CNY</span>
    </div>
</script>
<!--时间-->
<script type="text/html" id="create_atTpl" >
    <div>
        <span>添加：{{ d.create_at }}</span><br>
        <span>更新：{{ d.update_at }}</span><br>
        <span>采集人：{{ d.user_id_text }}</span><br>
        <span>更新人：{{ d.update_user_text }}</span>
    </div>
</script>
<!-- 认领平台 -->
<script type="text/html" id="claimTpl" >
    <div>
        {{#  layui.each(d.claim_platform, function(index, item){ }}
            <span>{{= item }}</span><br>
        {{#  }); }}
    </div>
</script>
{/block}
